FROM harbor.aixcoder.com/library/python:3.10-slim as builder

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

FROM harbor.aixcoder.com/library/python:3.10-slim

WORKDIR /app

#手动安装 apt-get update && apt-get install -y libreoffice --no-install-recommends

# 1. 先安装 tzdata（设置时区），再执行 apt-get update 和安装 libreoffice
# RUN apt-get update && \
#     apt-get install -y tzdata && \
#     ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
#     echo "Asia/Shanghai" > /etc/timezone && \
#     rm -f /etc/apt/sources.list.d/debian.sources && \
#     echo "Types: deb" > /etc/apt/sources.list.d/debian.sources && \
#     echo "URIs: http://mirrors.aliyun.com/debian" >> /etc/apt/sources.list.d/debian.sources && \
#     echo "Suites: bookworm" >> /etc/apt/sources.list.d/debian.sources && \
#     echo "Components: main contrib non-free" >> /etc/apt/sources.list.d/debian.sources && \
#     apt-get update && \
#     apt-get install -y libreoffice --no-install-recommends && \
#     apt-get clean && \
#     rm -rf /var/lib/apt/lists/*
RUN apt-get update && \
    apt-get install -y libreoffice --no-install-recommends && \
    apt-get install -y locales fonts-noto-cjk fonts-noto-cjk-extra fonts-wqy-zenhei fonts-wqy-microhei --no-install-recommends && \
    locale-gen zh_CN.UTF-8 && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
COPY --from=builder /app .

EXPOSE 9001

ENV FLASK_APP=router
ENV FLASK_ENV=production
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app
ENV LANG=zh_CN.UTF-8
ENV LC_ALL=zh_CN.UTF-8

RUN mkdir -p /var/log/formula2code && \
    chown -R 1000:1000 /var/log/formula2code && \
    chmod -R 755 /var/log/formula2code

CMD ["sh", "-c", "python router.py >> /var/log/formula2code/router.log 2>&1"]